home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 11282 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.0 KB

  1. Path: keats.ugrad.cs.ubc.ca!not-for-mail
  2. From: c2a192@ugrad.cs.ubc.ca (Kazimir Kylheku)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: timing in C
  5. Date: 22 Mar 1996 14:34:11 -0800
  6. Organization: Computer Science, University of B.C., Vancouver, B.C., Canada
  7. Message-ID: <4iv9t3INNbbk@keats.ugrad.cs.ubc.ca>
  8. References: <Pine.SOL.3.91.960322090413.3536A-100000@exp3.wam.umd.edu>
  9. NNTP-Posting-Host: keats.ugrad.cs.ubc.ca
  10.  
  11. In article <Pine.SOL.3.91.960322090413.3536A-100000@exp3.wam.umd.edu>,
  12. charles r marks  <chuckmx@wam.umd.edu> wrote:
  13. >How does one program timing into a C program? For example, I want to send 
  14. >an output signal every millisecond for a minute and then change to every 
  15. >other millisecond. 
  16.  
  17. The C standard does not define a real-time clock  or timer facilities. The best
  18. you can do is call clock() and loop around. There is a macro which tells you
  19. how many clock ticks to a second.
  20.  
  21. >Sorry for the neophyte question. Thanks for your help.
  22.  
  23. This is system specific. In a real-time kernel (or any multi-tasking kernel,
  24. really) it is usually not acceptable to poll for a clock since you waste CPU
  25. time. There will be some system-specific timer facilities provided, such as:
  26.  
  27. -    the ability to put the process to sleep until an alarm goes off;
  28.  
  29. -    or set up an interrupt timer that will call a signal handler routine
  30.     every so often. This may be good for what you want, since it gives
  31.     an accurate time base (provided the interrupt timer is real time,
  32.     rather than virtual process time).
  33.  
  34. -    ability to create timer objects, which you can reset/start/stop and
  35.     read at any time.
  36.  
  37. -    ``callout routines''---you make a special request to the kernel to
  38.     call a particular function with particular arguments at a particular
  39.     time. The request is enqueued, and the function gets called later.
  40.     Typical use: to turn off some signal (e.g. motor) after some delay
  41.     without using an interrupt or extra thread.
  42.  
  43. Find you what you can do under your system by consulting appropriate
  44. documentation, newsgroup, etc.
  45.  
  46.  
  47.  
  48. >Chuck Marks
  49.  
  50.  
  51. -- 
  52.  
  53.